package javbot.gui;


import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JPanel;

import javbot.RobotRunner;
import javbot.script.ScriptParser;

public class JavbotPanel extends JPanel {

	private static final long serialVersionUID = 906510024455580931L;
	public ScriptPanel scriptPanel = null;
	private JButton jButtonRun = null;
	/**
	 * This is the default constructor
	 */
	public JavbotPanel() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setLayout(new BorderLayout());
		this.setSize(300, 200);
		this.add(getScriptPanel(), java.awt.BorderLayout.CENTER);
	}

	/**
	 * This method initializes scriptPanel	
	 * 	
	 * @return jabot.gui.ScriptPanel	
	 */
	private ScriptPanel getScriptPanel() {
		if (scriptPanel == null) {
			scriptPanel = new ScriptPanel();
			scriptPanel.add(getJButtonRun(), java.awt.BorderLayout.SOUTH);
		}
		return scriptPanel;
	}

	/**
	 * This method initializes jButtonRun	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonRun() {
		if (jButtonRun == null) {
			jButtonRun = new JButton();
			jButtonRun.setText("Run");
			RobotRunner.setRunButton(jButtonRun);
			jButtonRun.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					if (!RobotRunner.isRunning())
						RobotRunner.runCommandList(ScriptParser.parseScript(scriptPanel.scriptInput.getText()));
					else 
						RobotRunner.stopRunning();		
				}					
			});
		}
		return jButtonRun;
	}

	public void setEnabled(boolean enabled) {
		super.setEnabled(enabled);
		jButtonRun.setEnabled(enabled);
		scriptPanel.setEnabled(enabled);
	}
	
	
}
